<?php
  /**
   * MVC Controller implements generic constructor.<br />
   * Use it and inherits all your MVC Controller classes from this one.
   *
   * @author Dany Mottier
   * @version 2.3.2
   */
  abstract class Controller extends Base {
    /**
     * @var object The model to work on.
     */
    protected $Model = NULL;
    
    /**
     * Store the model in private to work on.<br />
     * 
     * @param Base $Model the model to work on.
     *
     * @see <a href="http://be2.php.net/manual/en/function.is-object.php">is_object()</a>
     * @see <a href="http://be2.php.net/manual/en/function.str-replace.php">str_replace()</a>
     * @see <a href="http://be2.php.net/manual/en/function.get-class.php">get_class()</a>
     * @see IllegalArgumentException
     */
    public function __construct($Model) {
      if (is_object($Model) && (str_replace("Controller", "", get_class($this)) == str_replace("Model", "", get_class($Model)) || str_replace("Validator", "", get_class($this)) == str_replace("Model", "", get_class($Model))))
        $this->Model = $Model;
      else
        throw new IllegalArgumentException("The variable \$Model is not the associated Model.");
    }
    
    /**
     * Returns the model.<br />
     *
     * @return Base The model.
     */
    public function getObject() {
      return $this->Model;
    }

    /**
     * Sets the model in private.<br />
     *
     * @param object $Model The model to work on.
     *
     * @see <a href="http://be2.php.net/manual/en/function.is-object.php">is_object()</a>
     * @see <a href="http://be2.php.net/manual/en/function.str-replace.php">str_replace()</a>
     * @see <a href="http://be2.php.net/manual/en/function.get-class.php">get_class()</a>
     * @see IllegalArgumentException
     */
    public function setObject($Model) {
      if (is_object($Model) && str_replace("Controller", "", get_class($this)) == str_replace("Model", "", get_class($Model)))
        $this->Model = $Model;
      else
        throw new IllegalArgumentException("\$Model parameter should be the associated model.");
    }
    
  }
?>
